package com.example.mywork1;

import android.content.Context;
import android.os.Bundle;

import android.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class friendFragment extends Fragment {

    private RecyclerView recyclerView;
    private MyAdapter myAdapter;
    private List<Map<String,Object>> data;
    private Context context;

    public friendFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_friend, container, false);
        context=this.getActivity();
        recyclerView=view.findViewById(R.id.RecycleView);

        data=new ArrayList<Map<String,Object>>();
        String[] name={"爸爸","妈妈","姐姐","浩翔","格格","石头"};
        String[] area={"湖北","湖北","湖北","重庆","山西","湖北"};
        String[] age={"46","43","21","17","20","20"};
        int[] picture = {R.drawable.man, R.drawable.woman, R.drawable.woman, R.drawable.man,R.drawable.woman, R.drawable.woman};

        for (int i=0;i< name.length;i++) {
            Map<String,Object> map=new HashMap<String,Object>();
            map.put("照片", picture[i]);
            map.put("姓名",name[i]);
            map.put("地区",area[i]);
            map.put("年龄",age[i]);
            data.add(map);
        }

        myAdapter=new MyAdapter(data,context);
        LinearLayoutManager manager=new LinearLayoutManager(context);
        manager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(myAdapter);

        return view;
    }

}